import {
  deals,
  cilckRecord
} from '../../utils/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    records: [],
    sale: 0,
    loading: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.deals(JSON.parse(options.param))
  },
  deals(param) {
    deals(param).then(res => {
      this.setData({
        records: res.data.records,
        loading: false
      })
      let sale = 0
      this.data.records.forEach(e => {
        sale = sale + e.dealDetail.halfYearSale
      })
      this.setData({
        sale: sale
      })
    })
  },
  voucher(e) {
    wx.navigateToMiniProgram({
      appId: 'wxde8ac0a21135c07d',
      path: this.data.records[e.currentTarget.dataset.index].couponInfo.miniProgramUrl,
      success: res => {
        cilckRecord({
          actId: 1001,
        })
      }
    })
  }
})